<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of wall
 *
 * @author Andi
 */
include_once("database.php");

class wall extends database {
    //put your code here

    function  __construct() {
        $this->connect();
    }


    function showWallID($userName,$wallBody){
        $query = "SELECT * FROM wall WHERE user_name = '$userName' AND wall_body = '$wallBody'";
        $result = mysql_query($query);
        $row = mysql_fetch_array($result);
        $wallID = $row['wall_id'];
        return $wallID;
    }

    function sentWall($userName,$userNamePost,$wallBody){
        $date_now = date('Y-m-d');
        $time_now = strftime('%X');
        $sql = "INSERT INTO wall (user_name,user_name_post,wall_body,post_date,post_time) VALUE ('$userName','$userNamePost','$wallBody','$date_now','$time_now')";
        mysql_query($sql);
    }

    function showWall($userName){
        $sql = "SELECT * FROM wall WHERE user_name = '$userName' ORDER BY wall_id DESC";
        $result = mysql_query($sql);
        return $result;
    }

    function showWallByHakAkses($username, $hakakses){
        $sql = "SELECT * FROM wall,user WHERE wall.user_name = '$username' AND wall_prev = '$hakakses' AND wall.user_name = user.user_name";
        $result = mysql_query($sql);
        return $result;
    }
    

    function deleteWall($wallID){
        $this->delete('wall', 'wall_id', $wallID);
        $this->delete('wall_comment', 'wall_id', $wallID);
        $this->delete('wall_tag', 'wall_id', $wallID);
    }

    function sentWallCom($wallID,$userNameCom,$wallComBody){
        $date_now = date('Y-m-d');
        $time_now = strftime('%X');
        $sql = "INSERT INTO wall_comment (wall_id,user_name,wall_com_body,post_date,post_time) VALUE ('$wallID','$userNameCom','$wallComBody','$date_now','$time_now')";
        mysql_query($sql);
    }

    function showWallCom($wallID){
        $sql = "SELECT wall_com_id,wall_comment.user_name AS 'from',wall_com_body,wall_comment.post_date,wall_comment.post_time FROM wall,wall_comment WHERE wall.wall_id = '$wallID' AND wall.wall_id = wall_comment.wall_id";
        $result = mysql_query($sql);
        return $result;
    }

    function deleteWallCom($wallComID){
        $this->delete('wall_comment', 'wall_com_id', $wallComID);
    }

    function addWallTag($userName,$wallBody,$userNameTag){
        $wallID = $this->showWallID($userName, $wallBody);
        $sql = "INSERT INTO wall_tag (wall_id,user_name) VALUE ('$wallID','$userNameTag')";
        mysql_query($sql);
    }

    function showWallTag($userName,$wallBody){
        $wallID = $this->showWallID($userName, $wallBody);
        $sql = "SELECT * FROM wall_tag WHERE wall_id = '$wallID'";
        $result = mysql_query($sql);
        return $result;
    }

}
?>
